import request from "@/utils/axios.js";
import {ossBuckets} from "@/utils/oss.js";

export function getAllCopdReportByPage(reportStatus,params){
    return request.get(`/api/copd/getAllCOPDByPage/${reportStatus}`, {
        params: params
    })
}


export function getCopdReport(copdReportId){
    let obj = {
        method: "GET",
        showLoading: true,
        url: `/api/copd/getCopdReport`,
        params: {
            copdReportId: copdReportId
        },
        message: "正在获取数据"
    }
    return request(obj)
}

export function getEcgDataAPI(ossEcgFilePath,endpoint,bucketName,region,objectName){
    let obj = {
        method: "GET",
        showLoading: true,
        url: `/api/copd/getEcgData`,
        params: {
            ossEcgFilePath: ossEcgFilePath,
            endpoint:endpoint,
            bucketName:bucketName,
            region:region,
            objectName:objectName,
        },
        message: "正在获取ECG数据"
    }
    return request(obj)
}


export function getRespDataAPI(ossRespFilePath,endpoint,bucketName,region,objectName){
    let obj = {
        method: "GET",
        showLoading: true,
        url: `/api/copd/getRespData`,
        params: {
            ossEcgFilePath: ossRespFilePath,
            endpoint:endpoint,
            bucketName:bucketName,
            region:region,
            objectName:objectName,
        },
        message: "正在获取Resp数据"
    }
    return request(obj)
}


export function getUserDataByUid(userId,reportId){
    let obj = {
        method: "GET",
        showLoading: true,
        url: `/api/copd/getUserDataByUid/${userId}`,
        params: {
            reportId:reportId
        },
        message: "获取用户信息"
    }
    return request(obj)
}


export function updateCopdReport(copdReport){
    let obj = {
        method: "POST",
        showLoading: true,
        url: `/api/copd/updateCOPDData`,
        data: copdReport,
        message: "获取用户信息"
    }
    return request(obj)
}


export function getCopdReportData(reportId){
    let obj = {
        method: "GET",
        showLoading: false,
        url: `/api/copd/getData`,
        params: {
            copdReportId: reportId
        },
        message: "正在获取数据"
    }
    return request(obj)
}

export function getEcgData(reportId,startTimeTamp){
    let ecgBucket = ossBuckets.ecg;
    let ecgFileName = reportId + '_' + 'ecg_' + startTimeTamp + '.txt';

    const ecgHost = 'https://' + ecgBucket + '.oss-cn-chengdu.aliyuncs.com';
    // 生成上传时 OSS 完整的路径
    const ossEcgFilePath = ecgHost + "/" + reportId+'/'+ ecgFileName;

    const endpoint='oss-cn-chengdu.aliyuncs.com';
    const region="cn-chengdu"
    const ecgObjectName=reportId+'/'+ ecgFileName;
    return  getEcgDataAPI(ossEcgFilePath,endpoint,ecgBucket,region,ecgObjectName)

}


export function getRespData(reportId,startTimeTamp){

    let respBucket = ossBuckets.resp;
    let respFileName =  reportId + '_' + 'resp_' + startTimeTamp + '.txt';

    // 生成上传时 OSS 完整的路径

    const endpoint='oss-cn-chengdu.aliyuncs.com';
    const region="cn-chengdu"
    const respObjectName=reportId+'/'+ respFileName;

    return getRespDataAPI("ossFilePath",endpoint,respBucket,region,respObjectName)
}


